package com.example.analyzevisio.utis;


import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class HttpRestTemplate {
    public static void post(String body) {
        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
            // 要发送的URL
            String urlString = "http://192.168.17.56/agrs";

            // 创建HttpPost对象
            HttpPost post = new HttpPost(urlString);
            // 设置请求头
            post.setHeader("Content-type", "application/json");
            // 将body转换为StringEntity并设置到HttpPost对象
            post.setEntity(new StringEntity(body, "UTF-8"));

            // 执行请求并获取响应
            HttpResponse response = httpClient.execute(post);
            // 输出状态码
            System.out.println(response.getStatusLine().getStatusCode());
            // 读取响应内容
            String responseBody = EntityUtils.toString(response.getEntity(), "UTF-8");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
